<template>
  <div>
    <el-form ref="form" :label-position="left" label-width="130px" :model="form" >
      <el-form-item label="活动名称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="权限">
        <el-select v-model="form.scope" placeholder="请选择权限">
          <el-option label="all" value="all"></el-option>
          <el-option label="read" value="read"></el-option>
          <el-option label="write" value="write"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="认证类型">
        <el-select v-model="form.authorizedGrantTypes" placeholder="请选择认证类型">
          <el-option label="code" value="code"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="重定向地址">
        <el-input v-model="form.redirectUri"></el-input>
      </el-form-item>
      <el-form-item label="详细权限">
        <el-input v-model="form.authorities"></el-input>
      </el-form-item>
      <el-form-item label="access_token有效时间">
        <el-input v-model="form.accessTokenValidity" type="number"></el-input>
      </el-form-item>
      <el-form-item label="refresh_token有效时间">
        <el-input v-model="form.refreshTokenValidity" type="number"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.additionalInformation"></el-input>
      </el-form-item>
      <el-form-item label="自动通过">
        <el-select v-model="form.autoApprove" placeholder="请选择权限">
          <el-option label="true" value="1"></el-option>
          <el-option label="false" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="goback">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {clientAdd} from "../../request/api";
import {Message} from "_element-ui@2.15.6@element-ui";

export default {
  data() {
    return {
      form: {
        accessTokenValidity: 3600,
        additionalInformation: "",
        authorities: "",
        authorizedGrantTypes: "code",
        autoApprove: "2",
        name: "",
        redirectUri: "",
        refreshTokenValidity: 7200,
        scope: "all"
      }
    }
  },
  methods: {
    goback() {
      this.$router.go(-1)
    },
    onSubmit() {
      clientAdd(this.form).then(res=>{
        if(res.code != 0) {
          Message({
            showClose: true,
            message: res.msg,
            type: 'error'
          });
          return
        }
        Message({
          showClose: true,
          message: '新增成功',
          type: 'success'
        });
        this.$router.push('/oauth2/client/list')
      })
    }
  }
}
</script>